//
//  BlogsCell.m
//  oschina_song
//
//  Created by song on 16/1/28.
//  Copyright © 2016年 song. All rights reserved.
//

#import "BlogsCell.h"

@implementation BlogsCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight;
        
        [self initSubViews];
        [self initLayout];
    }
    
    return self;
    
}

-(void)initSubViews
{
    _titleLable =[[UILabel alloc] init];
    _titleLable.numberOfLines =0;
    _titleLable.lineBreakMode = NSLineBreakByWordWrapping;
    _titleLable.font =[UIFont boldSystemFontOfSize:15];
    [self.contentView addSubview:_titleLable];
    
    _bodyLabel = [[UILabel alloc] init];
    _bodyLabel.numberOfLines =0;
    _bodyLabel.lineBreakMode = NSLineBreakByWordWrapping;
    _bodyLabel.font =[UIFont systemFontOfSize:13];
    _bodyLabel.textColor = [UIColor grayColor];
    [self.contentView addSubview:_bodyLabel];
    
    _authorLabel = [[UILabel alloc] init];
    _authorLabel.font = [UIFont systemFontOfSize:12];
    _authorLabel.textColor = [UIColor grayColor];
    [self.contentView addSubview:_authorLabel];
    
    _timeLabel = [[UILabel alloc] init];
    _timeLabel.font = [UIFont systemFontOfSize:12];
    _timeLabel.textColor = [UIColor grayColor];
    [self.contentView addSubview:_timeLabel];
    
    _commentCount =[[UILabel alloc] init];
    _commentCount.font = [UIFont systemFontOfSize:12];
    _commentCount.textColor = [UIColor grayColor];
    [self.contentView addSubview:_commentCount];
    
}

-(void)initLayout
{
    for (UIView *view in [self.contentView subviews]) {
        view.translatesAutoresizingMaskIntoConstraints = NO;
    }
    
    NSDictionary *viewdic = NSDictionaryOfVariableBindings(_titleLable ,_bodyLabel ,_authorLabel ,_timeLabel,_commentCount);
    
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-8-[_titleLable]-5-[_bodyLabel]" options:NSLayoutFormatAlignAllLeft|NSLayoutFormatAlignAllRight metrics:nil views:viewdic]];
    
    
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_bodyLabel]-5-[_authorLabel]-8-|" options:NSLayoutFormatAlignAllLeft metrics:nil views:viewdic]];
    
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-8-[_titleLable]-8-|"
                                                                             options:0 metrics:nil views:viewdic]];
    
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[_authorLabel]-10-[_timeLabel]-10-[_commentCount]" options:NSLayoutFormatAlignAllTop|NSLayoutFormatAlignAllBottom metrics:nil views:viewdic]];
}



@end
